/**
 * 
 */
package com.momosw.games.jericho.actions;

import com.momosw.games.engine.Action;
import com.momosw.games.engine.Game;
import com.momosw.games.engine.events.ActionEvent;
import com.momosw.games.engine.events.Event;
import com.momosw.games.engine.player.Player;
import com.momosw.games.engine.util.Utils;
import com.momosw.games.jericho.board.Card;
import com.momosw.games.jericho.board.ScoringCard;
import com.momosw.games.jericho.board.WallType;

/**
 * <b>Project:</b> JerichoCardGame<br />
 * <b>Package:</b> com.momosw.games.jericho.actions<br />
 * <b>Class:</b> DrawCardAction.java<br />
 * <br />
 * <i>GSI 2011</i><br />
 *
 * @author Miguel Coronado (miguelcb84@gmail.com)
 * @version	Aug 17, 2011
 *
 */
public class DrawCardAction implements Action, ActionEvent {

    private Game game;
    private Player current;
    private Card card;
    
    /**
     * 
     * @param game
     * @param current
     */
    public DrawCardAction (Game game, Player current){
        this.game = game;
        this.current = current;
        this.card = null;
    }
    
    
    public void execute () {
        card = game.drawCard();
        if (card instanceof ScoringCard){
            Utils.notifyPlayers(game, current, this);
            
            game.scoringPhase ();
            card = game.drawCard();
        }
        current.addToHand(card);
        Utils.notifyPlayers(game, current, this);
    }

    public String getReadableName() {
        return "Robar carta";
    }
    
    @Override
    public String toString() {
        return "DrawCardAction";
    }

    /**
     * Duplicate the current action and hide the selected card, if any.
     */
    public Event hidePrivate() {
        return new DrawCardAction (game, current);
    }

    public Action getAction() {
        return this;
    }

    /**
     * The selected card if any. "Hidden-copies" of this action will have
     * no information about the card value.
     */
    public Card getCard() {
        return card;
    }

    /**
     * DrawCardActions never have associated WallTypes
     * @return null
     */
    public WallType getWallType() {
        return null;
    }

    public Player getPlayer() {
        return current;
    }

}
